package com.taskScheduler.task;

import java.util.concurrent.BlockingQueue;

public class PoolTask implements Runnable {
	// 基于ArrayBlockingQueue的阻塞队列
	private BlockingQueue<Runnable> runnableTaskqueue;
	private String srcIp;
	private String srcPort;
	private String srcFileName;
	private String dstIp;
	private String dstPort;

	public PoolTask(String srcIp, String srcPort, String srcFileName,
			String dstIp, String dstPort,
			BlockingQueue<Runnable> runnableTaskqueue) {
		this.srcIp = srcIp;
		this.srcPort = srcPort;
		this.srcFileName = srcFileName;
		this.dstIp = dstIp;
		this.dstPort = dstPort;
		this.runnableTaskqueue = runnableTaskqueue;
	}
	//creat poolTask by InstantTaskInfo
	public PoolTask(InstantTaskInfo instantTaskInfo,BlockingQueue<Runnable> runnableTaskqueue) {
		this.srcIp = instantTaskInfo.getSrcIp();
		this.srcPort = instantTaskInfo.getSrcPort();
		this.srcFileName = instantTaskInfo.getSrcFileName();
		this.dstIp = instantTaskInfo.getDstIp();
		this.dstPort = instantTaskInfo.getDstPort();
		this.runnableTaskqueue = runnableTaskqueue;
	}
	//creat poolTask by timingTaskInfo
	public PoolTask(TimingTaskInfo timingTaskInfo,BlockingQueue<Runnable> runnableTaskqueue) {
		this.srcIp = timingTaskInfo.getSrcIp();
		this.srcPort = timingTaskInfo.getSrcPort();
		this.srcFileName = timingTaskInfo.getSrcFileName();
		this.dstIp = timingTaskInfo.getDstIp();
		this.dstPort = timingTaskInfo.getDstPort();
		this.runnableTaskqueue = runnableTaskqueue;
	}
	//creat poolTask by periodicTaskInfo
	public PoolTask(PeriodicTaskInfo periodicTaskInfo,BlockingQueue<Runnable> runnableTaskqueue) {
		this.srcIp = periodicTaskInfo.getSrcIp();
		this.srcPort = periodicTaskInfo.getSrcPort();
		this.srcFileName = periodicTaskInfo.getSrcFileName();
		this.dstIp = periodicTaskInfo.getDstIp();
		this.dstPort = periodicTaskInfo.getDstPort();
		this.runnableTaskqueue = runnableTaskqueue;
	}
	@Override
	public void run() {
		// TODO Auto-generated method stub
		FileTransferTask fileTransferTask = new FileTransferTask(srcIp,
				srcPort, srcFileName, dstIp, dstPort);
		try {
			this.runnableTaskqueue.put(fileTransferTask);// 因为是阻塞队列（线程安全），将元素放入队尾，如果已满，则阻塞
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			// 以后会写入日志，并将此任务放入失败队列
			e.printStackTrace();
		}
	}

}
